<template>
  <div class="app-container">
    <el-form ref="user" :model="user" label-width="120px">
      <el-form-item label="玩家昵称">
        {{ user.name }}
      </el-form-item>
      <el-form-item label="uid">
        {{ user._uid }}
      </el-form-item>
      <el-form-item label="accountId">
        {{ user.accountId }}
      </el-form-item>
      <el-form-item label="金币">
        {{ user.gold }}
      </el-form-item>
      <el-form-item label="砖石">
        {{ user.diamon }}
      </el-form-item>
      <el-form-item label="盾牌">
        {{ user.shield }}
      </el-form-item>
      <el-form-item label="体力">
        {{ user.energy }}
      </el-form-item>
      <el-form-item label="当前关卡信息">
        <label> 第 {{ user.pos.lockBlockTid }} 关， 第 {{ user.pos.layerId }} 层</label>
      </el-form-item>
      <el-form-item label="最大关卡信息">
        <label> 第 {{ user.maxPos.lockBlockTid }} 关， 第 {{ user.maxPos.layerId }} 层 </label>
      </el-form-item>
      <el-form-item label="公会名称">
        [{{ union.shortName }}]{{ union.name }}
      </el-form-item>
      <el-form-item label="公会积分">
        {{ user.unionScore }}
      </el-form-item>
      <el-form-item label="注册时间">
        {{ user.registerTime | formatDate }}
      </el-form-item>
      <el-form-item label="地址端口">
        {{ addr }}
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
import { formatDate } from '@/utils/date'
import { getUserInfo } from '@/api/gameuser'
import { getUnionInfo } from '@/api/union'
import { userAddrList } from '@/api/loglist'

export default {
  filters: {
    formatDate(time) {
      var date = new Date(time * 1000)
      return formatDate(date, 'yyyy-MM-dd hh:mm:ss')
    }
  },
  data() {
    return {
      user: {
        _uid: '',
        name: '',
        gold: 0,
        accountId: '',
        energy: 0,
        lastLoginTime: 0,
        maxPos: {
          layerId: 0,
          layerOpenGridNum: 0,
          lockBlockTid: 0
        },
        pos: {
          layerId: 0,
          layerOpenGridNum: 0,
          lockBlockTid: 0
        },
        shield: 0,
        slotLv: 0,
        unionScore: 0,
        unionId: ''
      },
      union: {
        uid: '',
        name: '',
        shortName: ''
      },
      addr: ''
    }
  },
  created() {
    this.user.uid = this.$route.params && this.$route.params.uid
    this.fetchData()
  },
  methods: {
    fetchData() {
      getUserInfo(this.user.uid).then(response => {
        this.user = response.data.user
        if (this.user.unionId !== '') {
          getUnionInfo(this.user.unionId).then(response => {
            this.union = response.data.union
          })
        }
      })
      userAddrList(this.listQuery).then(response => {
        if (response.data.count > 0) {
          this.addr = response.data.logList[0].addr
        }
      })
    }
  }
}
</script>
